﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Indigo.Quibbler.Properties;

namespace Indigo.Quibbler.Controls
{
    /// <summary>
    /// Interaction logic for VideoArticleControl.xaml
    /// </summary>
    public partial class VideoArticleControl : UserControl
    {
        #region Constructor
        public VideoArticleControl()
        {
            InitializeComponent();
            
        }
        #endregion

        #region Properties
        public string Headline
        {
            get { return (string )GetValue(HeadlineProperty); }
            set { SetValue(HeadlineProperty, value); }
        }
        public static readonly DependencyProperty HeadlineProperty =
            DependencyProperty.Register("Headline", typeof(string ), typeof(VideoArticleControl), new UIPropertyMetadata(string.Empty));


        public string ImageUrl
        {
            get { return (string)GetValue(ImageUrlProperty); }
            set { SetValue(ImageUrlProperty, value); }
        }
        public static readonly DependencyProperty ImageUrlProperty =
            DependencyProperty.Register("ImageUrl", typeof(string), typeof(VideoArticleControl), new PropertyMetadata(string.Empty));


        public string VideoUrl
        {
            get { return (string )GetValue(VideoUrlProperty); }
            set { SetValue(VideoUrlProperty, value); }
        }
        public static readonly DependencyProperty VideoUrlProperty =
            DependencyProperty.Register("VideoUrl", typeof(string ), typeof(VideoArticleControl), new UIPropertyMetadata(string.Empty));

        public string SyncTime
        {
            get { return (string)GetValue(SyncTimeProperty); }
            set { SetValue(SyncTimeProperty, value); }
        }
        public static readonly DependencyProperty SyncTimeProperty = DependencyProperty.Register("SyncTime", typeof(string), typeof(VideoArticleControl), new PropertyMetadata(OnSyncTimeChanged));
        
        #endregion

        #region Event Handlers
        private static void OnSyncTimeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            (obj as VideoArticleControl).OnSyncTimeChanged(e);
        }
        private void OnSyncTimeChanged(DependencyPropertyChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.NewValue.ToString()))
            {
                if ((DateTime.Now - (new DateTime(long.Parse(e.NewValue.ToString())))).TotalMinutes <= Settings.Default.ContentUpdateFrequency)
                {
                    //Highlight the content. Its new.
                    borderArticle.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#BF81A2FC"));
                    txtHeadline.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFEF832C"));
                }
            }
        }
        #endregion
    }
}
